<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>上传Excel文件</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            text-align: center;
            margin: 50px;
        }
        .container {
            max-width: 400px;
            margin: auto;
            padding: 20px;
            border: 1px solid #ccc;
            border-radius: 10px;
        }
        input {
            margin: 10px 0;
        }
        .message {
            color: red;
            margin-top: 10px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>数据excel导入数据库过程</h1>

        <!-- 文件上传框 -->
        <input type="file" id="fileInput" accept=".xls,.xlsx">

        <!-- 文件类型选择框 -->
        <label for="dname">文件类型:</label>
        <select id="dname">
            <option value="d1">d1</option>
            <option value="d2">d2</option>
            <option value="d3">d3</option>
            <option value="d4">d4</option>
            <option value="d5">d5</option>
        </select>

        <button onclick="uploadFile()">上传</button>

        <p id="message" class="message"></p>
    </div>

    <script>
        function uploadFile() {
            const fileInput = document.getElementById("fileInput");
            const message = document.getElementById("message");
            const dname = document.getElementById("dname").value;  // 获取选择的文件类型

            if (!fileInput.files.length) {
                message.textContent = "请选择一个Excel文件上传。";
                return;
            }
            const file = fileInput.files[0];
            const formData = new FormData();
            formData.append("file", file);
            formData.append("dname", dname);  // 将文件类型dname作为参数附加到请求中

            fetch("http://127.0.0.1:8000/tiaojisystem/upload_excel/", {
                method: "POST",
                body: formData
            })
            .then(response => response.json())
            .then(data => {
                message.textContent = "文件上传成功！";
            })
            .catch(error => {
                message.textContent = "上传失败，请重试。";
            });
        }
    </script>
</body>
</html>
